<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Constants\ErrorCode;
use App\Constants\HttpStatus;
use App\Exception\DbException;
use App\Exception\ValidatorException;
use App\JsonRpc\RabbitMqService;
use App\Model\User;
use App\Service\QueueService;
use App\Service\UserQueueService;
use App\Service\UserService;
use http\Exception\BadHeaderException;
use Hyperf\Consul\KV;
use Hyperf\Contract\SessionInterface;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\ClientFactory;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Redis\Redis;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Utils\Coroutine;
use Hyperf\Utils\WaitGroup;
use Swoole\Coroutine\Channel;
use function foo\func;

/**
 * @Controller()
 * */
class UserController extends BaseController
{

    /**
     * @RequestMapping(path="index", methods="get")
     * */
    public function index(RequestInterface $request)
    {
        $user   = $request->input('user', 'Hyperf');
        $method = $request->getMethod();
        $user_info   = Db::table('user')->where('id', '=', 1)->first();
        var_dump($method);

        return [
            'method' => $method,
            'message' => "Hello {$user}.12345678",
            'user'      => $user_info,
            'DB_DRIVER'    => config('DB_DRIVER') ?? '获取该配置为空',
            'DB_HOST'    => config('DB_HOST') ?? '获取该配置为空',
        ];
    }

    /**
     * @RequestMapping(path="index", methods="post")
     * */
    public function create(RequestInterface $request)
    {

        return [
            'method' => 'post',
            'message' => "这是POST方法",
            'data2'      => $request->all(),
            'header'    => $request->header('ssid'),
        ];
    }

    /**
     * @RequestMapping(path="index", methods="put")
     * */
    public function update(RequestInterface $request)
    {
        $user_id   = $request->input('user_id', '1') + 0;
        $container = ApplicationContext::getContainer();
        $redis  = $container->get(Redis::class);

        return [
            'method' => 'put',
            'message' => "这是PUT方法",
        ];
    }

    /**
     *
     * @DeleteMapping(path="index")
     * */
    public function del(RequestInterface $request)
    {
        return [
            'method' => 'delete',
            'message' => "这是DELETE方法",
        ];
    }
}
